<?php
defined('IN_TS') or die('Access Denied.');

include 'groupinfo.php';

$title = $strGroup['groupname']."_财务公开";

//小组是否需要审核
if($strGroup['isaudit']=='1'){
	//推荐小组
	$arrRecommendGroup = $new['group']->getRecommendGroup('7');
	include template("group_isaudit");

}elseif($strGroup['isopen']=='1' && $isGroupUser=='0'){
	//是否开放访问
	include template("group_isopen");
}else{

    //获取并处理时间段
    $begintime = trim($_GET['begintime']);
    $endtime = trim($_GET['endtime']);
    if($begintime){
        if($endtime==''){
            $endtime=date('Y-m-d',time());
        }
    }

    if($endtime){
        if($begintime==''){
            $begintime='2017-10-08';
        }

        $endtime=date('Y-m-d',strtotime($endtime)).' 24:00';
    }

    $str = 'groupid='.$groupid;
    if($begintime!=''&& $endtime!=''){
        $str =$str.' and addtime>'.strtotime($begintime).' and addtime<'.strtotime($endtime);
        //$title = $title.date('ymd',strtotime($begintime)).'-'.date('ymd',strtotime($endtime));
    }

	$page = isset($_GET['page']) ? intval($_GET['page']) : 1;

	$lstart = $page*30-30;

    $url = tsUrl('group','acount',array('id'=>$groupid,'begintime'=>$begintime,'endtime'=>$endtime,'page'=>''));

    $arrAcount = $new['group']->findAll('group_acount',$str,'addtime desc',null,$lstart.',30');

    $strAcount = $new['group']->findAll('group_acount',$str);

	if( is_array($arrAcount)){
		foreach($arrAcount as $key=>$item){
			$arrAcount[$key]['user'] = aac('user')->getOneUser($item['userid']);
			$arrAcount[$key]['group'] = aac('group')->getOneGroup($item['groupid']);
		}
	}

    if($begintime||$endtime){
        $income = 0;
        $outcome = 0;
        foreach($strAcount as $k=> $item){
            if($item['type'] == 0){
                $outcome = $outcome+number_format($item['num'],2);
            }else{
                $income = $income+number_format($item['num'],2);
            }
        }
        $strGroup['income'] = number_format($income,2);
        $strGroup['outcome'] = number_format($outcome,2);
        $strGroup['surplus'] = number_format(($income - $outcome),2);
    }


	$acountNum = $new['group']->findCount('group_acount',$str.$andType);

	$pageUrl = pagination($acountNum, 30, $page, $url);


	//小组会员
	include 'groupuser.php';

	if($page > 1){
		$title = $strGroup['groupname'].' - 第'.$page.'页';
	}

	include template("acount");

}